/*
 * Modified sample code from mgwt showcase
 * Copyright 2010 Daniel Kurka
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package de.dhbw.vs.permachat.client;

import com.google.gwt.place.shared.PlaceController;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;

import de.dhbw.vs.permachat.client.activities.chat.ChatView;
import de.dhbw.vs.permachat.client.activities.chat.ChatViewGwtImpl;
import de.dhbw.vs.permachat.client.activities.chatroomlist.ChatRoomListView;
import de.dhbw.vs.permachat.client.activities.chatroomlist.ChatRoomListViewGwtImpl;
import de.dhbw.vs.permachat.client.activities.login.LoginView;
import de.dhbw.vs.permachat.client.activities.login.LoginViewGwtImpl;
import de.dhbw.vs.permachat.client.rest.ChatServiceAsync;

/**
 * @author flo
 * 
 */
public class ClientFactoryImpl implements ClientFactory {

	private EventBus eventBus;
	private PlaceController placeController;
	private ChatRoomListView chatRoomListViewImpl;
	private ChatView chatViewImpl;
	private LoginView loginViewImpl;
	
	//private ChatUser user;

	public ClientFactoryImpl() {
		eventBus = new SimpleEventBus();

		placeController = new PlaceController(eventBus);

		chatRoomListViewImpl = new ChatRoomListViewGwtImpl();
	}

	@Override
	public EventBus getEventBus() {
		return eventBus;
	}

	@Override
	public PlaceController getPlaceController() {
		return placeController;
	}

	@Override
	public ChatServiceAsync getChatService() {
		return ChatServiceAsync.Creator.get();
	}

	@Override
	public ChatRoomListView getChatRoomListView() {
		if(this.chatRoomListViewImpl == null){
			this.chatRoomListViewImpl = new ChatRoomListViewGwtImpl();
		}
		
		return this.chatRoomListViewImpl;
	}

	@Override
	public ChatView getChatView() {
		if(this.chatViewImpl == null){
			this.chatViewImpl = new ChatViewGwtImpl();
		}
		
		return this.chatViewImpl;
	}

	/*@Override
	public ChatUser getUser() {
		if(this.user == null){
			this.user = new ChatUser();
		}
		
		return this.user;
	}*/

	@Override
	public LoginView getLoginView() {
		if(this.loginViewImpl == null){
			this.loginViewImpl = new LoginViewGwtImpl();
		}
		
		return this.loginViewImpl;
	}

}
